Getting started
1. Hardware settings
DSPI eDMA Demo program requires the following hardware:
- TWR-K64F120M, FRDMK64F120M
2. Download program
- Download the program to the target board.
- Connect a USB cable to the PC host and open a serial terminal at 115200 baud, 8-bits no parity, 1 stop bit.
- When successfully connected, the program sends "Press spacebar to begin." to the terminal. Press the space key to continue. Communication Interface Settings:
- TWR-K64F120M(OpenSDA) UART1, TX: PTC3 RX: PTC4.
- FRDM-K64F120M(OpenSDA) UART0, TX: PTB16 RX: PTB17.
SPI Connections:TWR-K64F120M
Master | Slave
Signal | MCU | Board | Signal | MCU | Board
SS | PTD0 | (J11A-B46)| SS | PTB10 | (J11A-B9) SCK | PTD1 | (J11A-B48)| SCK | PTB11 | (J11A-B7) MstOut | PTD2 | (J11A-B45)| SlvIn | PTB17 | (J11A-B11) MstIn | PTD3 | (J11A-B44)| SlvOut | PTB16 | (J11A-B12)FRDM-K64F
Master | Slave
Signal | MCU | Board | Signal | MCU | Board
SS | PTD0 | (J2-6) | SS | PTD4 | (J6-4) SCK | PTD1 | (J2-12) | SCK | PTD5 | (J6-5) MstOut | PTD2 | (J2-8) | SlvIn | PTD7 | (J6-7) MstIn | PTD3 | (J2-10) | SlvOut | PTD6 | (J6-6)
3. Run the program
The following will appear in the terminal window:
DSPI eDMA Demo
DSPI Transfers using eDMA
Configuration:
| Setting | Value |
| Terminal Baud: | 115200 bps |
| TDSPI Bit rate: | 5000 bps |
| TDSPI Master: | DSPI0 |
| TDSPI Slave: | DSPI1 |
Connection on TWR-K64F120M:
| Master | Slave |
| SS PTD0 (J11A-B46) | PTB10 (J11A-B9) |
| SCK PTD1 (J11A-B48) | PTB11 (J11A-B7) |
| MstOut PTD2 (J11A-B45) | PTB17 (J11A-B11) SlvIn |
| MstIn PTD3 (J11A-B44) | PTB16 (J11A-B12) SlvOut |
Connection on FRDM-K64F120M:
| Master | Slave |
| SS PTD0 (J2-6) | PTD4 (J6-4) |
| SCK PTD1 (J2-12) | PTD5 (J6-5) |
| MstOut PTD2 (J2-8) | PTD7 (J6-7) SlvIn |
| MstIn PTD3 (J2-10) | PTD6 (J6-6) SlvOut |
This indicates the speed of the SPI transfers, and what pins to connect and how to connect them.
Key Functions
1.
void dspi_edma_master_setup(uint8_t instance, uint32_t baudRateHz, uint8_t transferSizeBits)Takes in the DSPI module instance, the desired data rate of DSPI transfers, and the frame size of the data transfer. Initializes master instance of DSPI.
- Parameters
-
| instance | DSPI module instance |
| baudRateHz | Pass in the desired baud rate of DSPI transfers in Hz. |
| transferSizeBits | Pass data frame size (8 or 16 bit) |
2.
void dspi_edma_slave_setup(uint8_t instance, uint8_t transferSizeBits)Takes in the DSPI module instance, and the frame size of the data transfer. Initializes slave instance of DSPI.
- Parameters
-
| instance | DSPI module instance |
| transferSizeBits | Pass data frame size (8 or 16 bit) |
3.
dspi_status_t data_source(uint8_t * sourceWord, uint32_t instance)Callback function for DSPI slave. Used to transmit data from slave. In this application it generates slave data out, the data out is a count.
- Parameters
-
| sourceWord | 8-bit data variable to be passed to slave PUSHR register. |
| instance | Instance of the DSPI module. |
4.
void
on_error(dspi_status_t error, uint32_t instance)Callback function for DSPI slave. Used to handle errors. In this application is sets the error flag to signal the end of the demonstration.
- Parameters
-
| error | Uses dspi_status_t value given by driver interrupt handler. |
| instance | Instance of the DSPI module. |
5.
void setup_edma_loop(
edma_loop_setup_t *loopSetup, uart_state_t *uart)Configures an eDMA transfer loop using a loopSetup structure, and if a valid uart_state_t is passed will print out the TCD for that loop.
- Parameters
-
| loopSetup | Data structure defined by user, containing all the parameters for the eDMA loop. |
| uart | Pointer to a valid uart_state_t for debug printing. |
6.
void disable_edma_loop(
edma_loop_setup_t *loopSetup, uart_state_t *uart)Disables user configured eDMA transfer loop. Also, will free memory allocated by eDMA transfer loop. If a valid uart_state_t is passed will print out the TCD for that loop.
- Parameters
-
| loopSetup | Data structure defined by user, containing all the parameters for the eDMA loop. |
| uart | Pointer to a valid uart_state_t for debug printing. |
7.
void *mem_align(size_t ptrSize, uint32_t alignment)Function to perform aligned data memory allocation. Useful when mem_align is not available.
- Parameters
-
| ptrSize | size_t variable to pass size of memory to be allocated |
| alignment | uint32_t variable to pass byte size to align data with |
- Returns
- pointer to aligned & allocated memory
8.
void
free_align(void *ptr)Function to free memory allocated by mem_align
- Parameters
-
| ptr | pointer that has been allocated with mem_align |